package com.atguigu.delivery.servlet;

import com.atguigu.delivery.entity.Company;
import com.atguigu.delivery.service.api.CompanyService;
import com.atguigu.delivery.service.impl.CompanyServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/DeliveryServletToAddPage")
public class DeliveryServletToAddPage extends HttpServlet {

    private CompanyService companyService = new CompanyServiceImpl();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、调用 Service 方法查询全部公司数据
        List<Company> companyList = companyService.getAllCompanyList();

        // 2、把数据存入请求域
        request.setAttribute("companyList", companyList);

        // 3、转发到添加页面
        request.getRequestDispatcher("/add.jsp").forward(request, response);
    }
}
